package terms;

/**
 * 11 avr. 2012.
 * @author Pierre Reliquet, Simon Devineau.
 *         Ecole des Mines de Nantes.
 *         Major in Information and Communications Systems Engineering.
 *         Function.java
 */
public class Function {
    /**
     * The name of the function.
     */
    private String  functionName;
    /**
     * The numbers of parameters of the function.
     */
    private Integer arity;

    /**
     * The default constructor.
     */
    public Function() {
        this.functionName = "";
        this.arity = 0;
    }

    /**
     * A constructor with the name of the
     * function and the number of parameters as parameters.
     * @param aName
     *            the name of the function.
     * @param aParametersNumber
     *            the number of parameters of the function.
     */
    public Function(final String aName, final Integer aParametersNumber) {
        this.functionName = aName;
        this.arity = aParametersNumber;
    }

    @Override
    public boolean equals(final Object aArg0) {
        boolean toReturn = false;
        if (aArg0 instanceof Function) {
            toReturn = this.functionName.equals(((Function) aArg0)
                    .getFunctionName())
                    && this.arity == ((Function) aArg0).getArity();
        }
        return toReturn;
    }

    /**
     * @return the arity
     */
    public final Integer getArity() {
        return this.arity;
    }

    /**
     * @return the functionName
     */
    public final String getFunctionName() {
        return this.functionName;
    }

    @Override
    public int hashCode() {
        return this.getFunctionName().hashCode() + this.getArity().hashCode();
    }

    /**
     * @param anArity
     *            the arity to set
     */
    public final void setArity(final Integer anArity) {
        this.arity = anArity;
    }

    /**
     * @param aFunctionName
     *            the functionName to set
     */
    public final void setFunctionName(final String aFunctionName) {
        this.functionName = aFunctionName;
    }

    @Override
    public String toString() {
        return this.functionName + " with " + this.arity + " parameters";
    }
}
